//
//  SpecCollectionViewCell.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/20.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//  规格Cell

#import "SpecCollectionViewCell.h"

@implementation SpecCollectionViewReusableView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        UIView *useLineView = [[UIView alloc] init];
        useLineView.backgroundColor = ButtonBackGroundColor;
        [self addSubview:useLineView];
        self.useLineView = useLineView;
        
        UILabel *useLabel = [[UILabel alloc] init];
        useLabel.font = BoldMidBigFont;
        useLabel.text = @"适用项目";
        [self addSubview:useLabel];
        self.useLabel = useLabel;
        
        
        UIButton *moreBtn = [[UIButton alloc] init];
        [moreBtn setTitle:@"查看更多"];
        [moreBtn setTitleColor:CSColorFromRGB(0x999999)];
        moreBtn.titleLabel.font = SmallFont;
        [self addSubview:moreBtn];
        self.moreBtn = moreBtn;
        
        TTTAttributedLabel *useDetailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        useDetailLabel.font = SmallFont;
        useDetailLabel.textColor = CSColorFromRGB(0x333333);
        useDetailLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        useDetailLabel.numberOfLines = 1;
        useDetailLabel.lineSpacing = 5;
        useDetailLabel.text = @"使用项目、完美世界";
        [self addSubview:useDetailLabel];
        self.useDetailLabel = useDetailLabel;;
        
        UIView *separLineView = [[UIView alloc] init];
        separLineView.backgroundColor = BackGroundColor;
        [self addSubview:separLineView];
        self.separLineView = separLineView;
        
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = ButtonBackGroundColor;
        [self addSubview:lineView];
        self.lineView = lineView;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = BoldMidBigFont;
        titleLabel.text = @"规格";
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIImageView *memImageView = [[UIImageView alloc] init];
        memImageView.image = [UIImage imageNamed:@"currencycard_format_icon_workersee_small"];
        [self addSubview:memImageView];
        self.memImageView = memImageView;
        
        UILabel *detailLabel = [[UILabel alloc] init];
        detailLabel.font = [UIFont systemFontOfSize:13.0];
        detailLabel.textColor = CSColorFromRGB(0x999999);
        detailLabel.text = @"表示该规格仅工作人员可见";
        [self addSubview:detailLabel];
        self.detailLabel = detailLabel;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    
    [self.useLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(15);
        
        make.width.mas_equalTo(3);
        
        make.height.mas_equalTo(self.useLabel);
        
        make.top.mas_equalTo(self).offset(12);
    }];
    
    [self.useLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.useLineView);
        
        make.left.mas_equalTo(self.useLineView.mas_right).offset(5);
        
        make.right.mas_equalTo(self.moreBtn.mas_left).offset(-3);
    }];
    
    
    [self.moreBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.useLineView);
        
        make.width.mas_equalTo(80);
        
        make.right.mas_equalTo(self).offset(-10);
    }];
    
    [self.useDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.useLineView.mas_bottom).offset(10);
        
        make.left.mas_equalTo(self.useLineView);
        
        make.right.mas_equalTo(self).offset(-10);
        
    }];
    
    [self.separLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.useDetailLabel.mas_bottom).offset(8);
        
        make.left.width.mas_equalTo(self);
        
        make.height.mas_equalTo(10);
    }];
    
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.useLineView);
        
        make.width.mas_equalTo(3);
        
        make.height.mas_equalTo(self.titleLabel);
        
        make.top.mas_equalTo(self.separLineView.mas_bottom).offset(12);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.lineView);
        
        make.left.mas_equalTo(self.lineView.mas_right).offset(5);
    }];
    
    [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.lineView);
        
        make.right.mas_equalTo(self).offset(-15);
    }];
    
    [self.memImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.lineView);
        
        make.right.mas_equalTo(self.detailLabel.mas_left).offset(-5);
    }];
}

@end

@implementation SpecCollectionViewCell

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.layer.borderWidth = 1;
        self.layer.borderColor = CSColorFromRGB(0xe9e9e9).CGColor;
        self.layer.cornerRadius = 2;
        self.layer.masksToBounds = YES;
        
        /**
         价格
         */
        UILabel *priceLabel = [[UILabel alloc] init];
        priceLabel.font = [UIFont systemFontOfSize:20.0];
        priceLabel.text = @"100元";
        [self addSubview:priceLabel];
        self.priceLabel = priceLabel;


        UILabel *validityTimeLabel = [[UILabel alloc] init];
        validityTimeLabel.text = @"365天";
        validityTimeLabel.font = SmallFont;
        validityTimeLabel.textColor = CSColorFromRGB(0x666666);
        [self addSubview:validityTimeLabel];
        self.validityTimeLabel = validityTimeLabel;

        /**
         详情
         */
        UILabel *userLabel = [[UILabel alloc] init];
        userLabel.text = @"在线购卡、在线充值";
        userLabel.font = SmallFont;
        userLabel.textColor = CSColorFromRGB(0x666666);
        [self addSubview:userLabel];
        self.userLabel = userLabel;;
        
        UIButton *addBtn = [[UIButton alloc] init];
        addBtn.userInteractionEnabled = NO;
        addBtn.hidden = YES;
        [addBtn setImage:@"icon_addlist"];
        [self addSubview:addBtn];
        self.addBtn = addBtn;
        
        UIImageView *memImageView = [[UIImageView alloc] init];
        memImageView.image = [UIImage imageNamed:@"currencycard_format_icon_workersee_big"];
        [self addSubview:memImageView];
        self.memImageView = memImageView;
        
        UIImageView *selectImageView = [[UIImageView alloc] init];
        selectImageView.hidden = YES;
        selectImageView.image = [UIImage imageNamed:@"carddetail_bt_selected"];
        [self addSubview:selectImageView];
        self.selectImageView = selectImageView;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    
    [self.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self);
    }];
    
    /**
     价格
     */
    [self.priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.left.mas_equalTo(self).offset(13);
    }];

    /**
     详情
     */
    [self.userLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.bottom.mas_equalTo(self).offset(-13);

        make.left.mas_equalTo(self.priceLabel);
    }];


    [self.validityTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(self.userLabel);

        make.bottom.mas_equalTo(self.userLabel.mas_top).offset(-5);
    }];
    
    [self.memImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.priceLabel);
        
        make.right.mas_equalTo(self).offset(-10);
    }];
    
    [self.selectImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.right.mas_equalTo(self);
    }];
}

-(void)setIsLast:(BOOL)isLast{
    
    _isLast = isLast;

    if (_isLast) {

        /**
         价格
         */
        self.priceLabel.hidden = YES;

        /**
         有效期
         */
        self.validityTimeLabel.hidden = YES;

        /**
         适用
         */
        self.userLabel.hidden = YES;
        
        self.memImageView.hidden = YES;
        
        self.addBtn.hidden = NO;
    }
    else{

        /**
         价格
         */
        self.priceLabel.hidden = NO;

        /**
         有效期
         */
        self.validityTimeLabel.hidden = NO;

        /**
         适用
         */
        self.userLabel.hidden = NO;
        
        self.addBtn.hidden = YES;
    }
}


-(void)setIsMem:(BOOL)isMem{
    
    _isMem = isMem;
    
    if (isMem) {
        
        self.memImageView.hidden = NO;
    }
    else{
        
        self.memImageView.hidden = YES;
    }
}

-(void)setSpecDict:(NSMutableDictionary *)specDict{
    
    _specDict = specDict;
    
    //是否仅工作人员可见
    
    BOOL IsOnlyWorker = [[specDict objectForKey:@"IsOnlyWorker"] boolValue];
    
    if (IsOnlyWorker) {
        
        self.memImageView.hidden = NO;
    }
    else{
        
        self.memImageView.hidden = YES;
    }
    
    //在线购卡
    BOOL IsBuy = [[specDict objectForKey:@"IsBuy"] boolValue];
    
    if (IsBuy) {
        
        self.userLabel.text = @"在线购卡";
    }
    //在线购卡
    BOOL IsRecharge = [[specDict objectForKey:@"IsRecharge"] boolValue];
    
    if (IsBuy && IsRecharge) {
        
        self.userLabel.text = @"在线购卡、在线充值";
    }
    else if (IsRecharge){
        
        self.userLabel.text = @"在线购卡";
    }
    
    //储值
    if ([self.cardType intValue] == Value){
        
        self.priceLabel.text = [NSString stringWithFormat:@"%@元",[specDict objectForKey:@"Times"]];
        
        //期限
        BOOL IsValidityDay = [[specDict objectForKey:@"IsValidityDay"] boolValue];
        
        //有设置期限
        if (IsValidityDay) {
            
            self.validityTimeLabel.text = [NSString stringWithFormat:@"有效期:%@天",[specDict objectForKey:@"ValidityDay"]];
        }
        else{
            
            self.validityTimeLabel.text = @"没有期限";
        }
        
    }
    
    //次卡
    if ([self.cardType intValue] == Time) {
        
        self.priceLabel.text = [NSString stringWithFormat:@"%@次",[specDict objectForKey:@"Times"]];
        
        //期限
        BOOL IsValidityDay = [[specDict objectForKey:@"IsValidityDay"] boolValue];
        
        //有设置期限
        if (IsValidityDay) {
            
            self.validityTimeLabel.text = [NSString stringWithFormat:@"有效期:%@天",[specDict objectForKey:@"ValidityDay"]];
        }
        else{
            
            self.validityTimeLabel.text = @"没有期限";
        }
    }
    
    //期限卡
    if ([self.cardType intValue] == Term) {
        
        self.priceLabel.text = [NSString stringWithFormat:@"%@天",[specDict objectForKey:@"Times"]];
        
        self.validityTimeLabel.text = @"";
        
        /**
         价格
         */
        [self.priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.left.mas_equalTo(self).offset(20);
        }];
        
        /**
         详情
         */
        [self.userLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.mas_equalTo(self).offset(-20);
            
            make.left.mas_equalTo(self.priceLabel);
        }];
    }
}


-(void)setIsOther:(BOOL)isOther{
    
    _isOther = isOther;
    
    self.memImageView.hidden = YES;
    
    [self.addBtn setImage:@""];
    
    //其他
    if (isOther) {
        
        /**
         价格
         */
        self.priceLabel.hidden = YES;
        
        /**
         有效期
         */
        self.validityTimeLabel.hidden = YES;
        
        /**
         适用
         */
        self.userLabel.hidden = YES;
        
        self.memImageView.hidden = YES;
        
        self.addBtn.hidden = NO;
        
        [self.addBtn setTitle:@"其他"];
        
        [self.addBtn setTitleColor:CSColorFromRGB(0x333333)];
        
        self.addBtn.titleLabel.font = MidBigFont;
    }
    else{
        
        /**
         价格
         */
        self.priceLabel.hidden = NO;
        
        /**
         有效期
         */
        self.validityTimeLabel.hidden = NO;
        
        /**
         适用
         */
        self.userLabel.hidden = NO;
        
        self.addBtn.hidden = YES;
    }
}

-(void)setIsSelect:(BOOL)isSelect{
    
    _isSelect = isSelect;
    
    if (isSelect) {
    
        self.selectImageView.hidden = NO;
        
    }
    else{
        
        self.selectImageView.hidden = YES;
    }
}
@end
